package net.lcheng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.lcheng.commons.utils.PageList;
import net.lcheng.dao.PCategoryAttributeValueMapper;
import net.lcheng.model.PCategoryAttributeValue;
import net.lcheng.model.PCategoryAttributeValueExample;
import net.lcheng.service.CategoryAttributeValService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by LV on 2016/6/27.
 */
@Service("categoryAttributeValService")
public class CategoryAttributeValServiceImpl implements CategoryAttributeValService {
    @Resource
    private PCategoryAttributeValueMapper pCategoryAttributeValueMapper;

    /**
     * 添加属性分类值
     * @param pCategoryAttributeValue
     * @return
     */
    @Override
    public int addCategoryAttributeVal(PCategoryAttributeValue pCategoryAttributeValue) {
        return pCategoryAttributeValueMapper.insertSelective(pCategoryAttributeValue);
    }

    /**
     * 查找分类属性的属性值列表
     * @param attributeId
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @Override
    public PageList<PCategoryAttributeValue> findAllCategoryAttributeValue(String attributeId, int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);

        //select all attribute list by categoryId
        PCategoryAttributeValueExample example=new PCategoryAttributeValueExample();
        example.createCriteria().andPCategoryAttributeAttributeIdEqualTo(attributeId);
        List<PCategoryAttributeValue> list =pCategoryAttributeValueMapper.selectByExample(example);

        PageInfo<PCategoryAttributeValue> pageInfo=new PageInfo<>(list);
        PageList<PCategoryAttributeValue> pageList=new PageList<>();
        pageList.list=pageInfo.getList();
        pageList.pageIndex=pageInfo.getPageNum();
        pageList.pageSize=pageInfo.getPageSize();
        pageList.totalPage=pageInfo.getPages();
        pageList.totalCount=pageInfo.getTotal();

        return pageList;

    }

    /**
     * 查找指定主键分类属性值
     * @param attributeValId
     * @return
     */
    @Override
    public PCategoryAttributeValue findCategoryAttributeValByPrimaryKey(String attributeValId) {

        return  pCategoryAttributeValueMapper.selectByPrimaryKey(attributeValId);
    }

    /**
     * 修改指定的主键的分类属性值
     * @param attributeValue
     * @return
     */
    @Override
    public int updateCategoryAttributeValByPrimaryKey(PCategoryAttributeValue attributeValue) {
        return pCategoryAttributeValueMapper.updateByPrimaryKeySelective(attributeValue);
    }

    /**
     * 删除指定主键的分类属性值
     * @param attributeValId
     * @return
     */
    @Override
    public int deleteCategoryAttributeValByPrimaryKey(String attributeValId) {
        return pCategoryAttributeValueMapper.deleteByPrimaryKey(attributeValId);
    }


}
